package AsLayers.Geometry
{
	public class Collection implements IGeometry
	{
		private var components:Array=new Array()
		private var componentTypes:Array=null
		private var parent:IGeometry
		public function Collection(components:Array) 
		{
			this.components=components;
			this.addComponents(components);
		}
		public function addComponents(components:Array):void{
			for(var i:int=0;i<components.length;i++){
				this.addComponent(components[i])
			}
		}
		public function addComponent(component:IGeometry, index:int=-1):Boolean{
			var added:Boolean = false;
            if(this.componentTypes == null||this.componentTypes.indexOf(component.getGeometryName(),0)>-1) {

                if(index != -1 && (index < this.components.length)) {
                    var components1 = this.components.slice(0, index);
                    var components2 = this.components.slice(index, 
                                                           this.components.length);
                    components1.push(component);
                    this.components = components1.concat(components2);
                } else {
                    this.components.push(component);
                }
                component.setParent(this);
                //this.clearBounds();
                added = true;
            }
            return added;
		}
		public function getArea():Number{
			return 0
		}
		public function getLength():Number{
			return 0
		}
		public function toString():String{
			return ""
		}
		public function getGeometryName():String{
			return "Collection"
		}
		public function setParent(geo:IGeometry):void{
			this.parent=geo;
		}
		public function getParent():IGeometry{
			return this.parent
		}
	}
}